﻿using System.Collections.Generic;
using System.Text;
using System.Web;

namespace masterview.Code
{
    public static class AppContentHelper
    {
        #region private members

        private const string OnLoad = "onLoad.js";
        private const string Notifier = "notifier.js";
        private const string JQuery = "jquery-1.6.4.js";
        private const string CssTemplate = "<link href='{0}' rel='stylesheet' type='text/css'/>";
        private const string JavaScriptTemplate = "<script src='{0}' language='javascript' type='text/javascript'></script>";

        #endregion

        #region private methods

        #region roots
        private static string ContentRoot
        {
            get
            {
                const string contentVirtualRoot = "~/Content";
                return VirtualPathUtility.ToAbsolute(contentVirtualRoot);
            }
        }

        private static string GetImageRoot
        {
            get { return string.Format("{0}/{1}", ContentRoot, "Images"); }
        }

        private static string GetCssRoot
        {
            get { return string.Format("{0}/{1}", ContentRoot, "Css"); }
        }

        private static string GetJsRoot
        {
            get { return string.Format("{0}/{1}", ContentRoot, "Js"); }
        }
        #endregion

        #region urls
        private static string GetJQueryUrl()
        {
            return string.Format("{0}/{1}", GetJsRoot, JQuery);
        }

        private static string GetImageUrl(string imageFile)
        {
            return string.Format("{0}/{1}", GetImageRoot, imageFile);
        }

        private static string GetCssUrl(string cssFile)
        {
            return string.Format("{0}/{1}", GetCssRoot, cssFile);
        }

        private static string GetJsUrl(string jsFile)
        {
            return string.Format("{0}/{1}", GetJsRoot, jsFile);
        }
        #endregion

        private static string GetContent(string contentString)
        {
            return "\r\n" + contentString;
        }

        #endregion

        #region public methods

        public static string GetJs(string jsFile)
        {
            return GetContent(string.Format(JavaScriptTemplate, GetJsUrl(jsFile)));
        }

        public static string GetCss(string cssFile)
        {
            return GetContent(string.Format(CssTemplate, GetCssUrl(cssFile)));
        }

        public static string GetJQuery()
        {
            return GetContent(string.Format(JavaScriptTemplate, GetJQueryUrl()));
        }

        public static string GetNotifier()
        {
            return GetContent(string.Format(JavaScriptTemplate, GetJsUrl(Notifier)));
        }

        #endregion

        public static string GetPrepatedHeader()
        {
            var sb = new StringBuilder();

            sb.Append(GetJQuery());
            sb.Append(GetNotifier());
            sb.Append(GetJs(OnLoad));

            return sb.ToString();
        }
    }
}